package com.community.web.controller.communityInteraction;

import com.community.body.domain.ZyComment;
import com.community.body.dto.CommentDTO;
import com.community.body.service.IZyCommentService;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.core.page.TableDataInfo;
import com.community.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论Controller
 * 
 * @author community
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/oschina/comment")
public class ZyCommentController extends BaseController
{
    @Autowired
    private IZyCommentService zyCommentService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('oschina:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyComment zyComment)
    {
//        startPage();
        List<CommentDTO> list = zyCommentService.selectZyCommentList(zyComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
//    @PreAuthorize("@ss.hasPermi('oschina:comment:export')")
//    @Log(title = "评论", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZyComment zyComment)
//    {
//        List<CommentDTO> list = zyCommentService.selectZyCommentList(zyComment);
//        ExcelUtil<ZyComment> util = new ExcelUtil<ZyComment>(ZyComment.class);
//        util.exportExcel(response, list, "评论数据");
//    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('oschina:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(zyCommentService.selectZyCommentByCommentId(commentId));
    }

    /**
     * 新增评论
     */
//    @PreAuthorize("@ss.hasPermi('oschina:comment:add')")
//    @Log(title = "评论", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody ZyComment zyComment)
//    {
//        return toAjax(zyCommentService.insertZyComment(zyComment));
//    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('oschina:comment:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyComment zyComment)
    {
        return toAjax(zyCommentService.updateZyComment(zyComment));
    }

    /**
     * 批量删除评论
     */
    @PreAuthorize("@ss.hasPermi('oschina:comment:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(zyCommentService.deleteZyCommentByCommentIds(commentIds));
    }
}
